#pragma once

#include <stdio.h>
#include <time.h>

#define INF 0
#define DBG 1
#define ERR 2
#define DEFAULT_LOG_LEVEL DBG

// %s %d 格式  [15:30:24 main.c:25] 调试信息  只有正常信息才打印，错误信息跳过
#define LOG(level, format, ...)                                                                \
    do                                                                                         \
    {                                                                                          \
        if (level < DEFAULT_LOG_LEVEL)                                                         \
            break;                                                                             \
        time_t t = time(NULL);                                                                 \
        struct tm *lt = localtime(&t);                                                         \
        char buffer[32] = {0};                                                                 \
        strftime(buffer, 31, "%H:%M:%S", lt);                                                  \
        fprintf(stdout, "[%s %s:%d] " format "\n", buffer, __FILE__, __LINE__, ##__VA_ARGS__); \
    } while (0)

#define ILOG(format, ...) LOG(INF, format, ##__VA_ARGS__);
#define DLOG(format, ...) LOG(DBG, format, ##__VA_ARGS__);
#define ELOG(format, ...) LOG(ERR, format, ##__VA_ARGS__);
